<?php
namespace App\Services\Adv;
use App\Services\Adv\Adv\AdvLogic;
/**
 * @Author: ws
 * @Date:   2018-06-12 16:23:45
 * @Last Modified by:   Marte
 */
class Adv
{
    // 广告位添加
    public function addAdv($data)
    {
        $data = init_array($data, ['name' =>'','order'=>'','jump_url'=>'']);
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        ValidateAdv::checkValidate($data, ['name', 'order','jump_url']);
        return (new AdvLogic())->addAdv($data);
    }

     // 获取某个广告位详情
    public function advInfo($data)
    {
        $data = init_array($data, ['id' => 0]);
        ValidateAdv::checkValidate($data, ['id']);
        return (new AdvLogic())->advInfo($data);
    }
    // 广告位编辑
    public function advEdit($data): array
    {
       if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $data = init_array($data, ['id' => 0,'name' => '','jump_url' => '','order' => '']);
        ValidateAdv::checkValidate($data, ["id", "name", "jump_url", "order"]);
        return (new AdvLogic())->advEdit($data);
    }
     // 删除某个广告位
    public function advDelete($data)
    {
        $data = init_array($data, ['id' => 0]);
        ValidateAdv::checkValidate($data, ['id']);
        return (new AdvLogic())->advDelete($data);
    }
    // 启用某个广告位
    public function advEnable($data)
    {
        $data = init_array($data, ['id' => 0]);
        ValidateAdv::checkValidate($data, ['id']);
        return (new AdvLogic())->advEnable($data);
    }
    // 禁用某个广告位
    public function advDisable($data)
    {
        $data = init_array($data, ['id' => 0]);
        ValidateAdv::checkValidate($data, ['id']);
        return (new AdvLogic())->advDisable($data);
    }
    // 审核通过某个广告位
    public function advAudit($data)
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $initMap = ["id" => " ", "auditor_id" => ""];
        $data = init_array($data, $initMap);
        ValidateAdv::checkValidate($data, array_keys($initMap));
        return (new AdvLogic())->advAudit($data);
    }
     // 审核失败/不通过某个广告位
    public function advAuditFailure($data)
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $initMap = ["id" => " ", "auditor_id" => ""];
        $data = init_array($data, $initMap);
        ValidateAdv::checkValidate($data, array_keys($initMap));
        return (new AdvLogic())->advAuditFailure($data);
    }
     // 某一类广告位列表获取  根据c_id或action进行获取
    public function advClassList($data)
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $data = init_array($data, ['c_id' => 0,"listRows" => "15", "page" => "1"]);
        ValidateAdv::checkValidate($data, ['page', 'listRows']);
        return (new AdvLogic())->advClassList($data);
    }
      // 不同状态广告位列表获取
    public function advDifferenceStatus($data)
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $data = init_array($data, ["audit_status" => "1", "listRows" => "15", "page" => "1"]);
        ValidateAdv::checkValidate($data, ['c_id', 'page', 'listRows']);
        return (new AdvLogic())->advDifferenceStatus($data);
    }
    // 全部广告位列表获取
    public function advList($data)
    {
        $data = init_array($data, ['page' => 1, 'listRows' => 15]);
        ValidateAdv::checkValidate($data, ['page', 'listRows']);
       return (new AdvLogic())->advList($data);
    }
    //规定上架时间内 正常状态 审核通过的广告位等
    public function advTimeLimit($data)
    {

        $data = init_array($data, ['action','c_id'=>'','limit'=>5]);
        //ValidateAdv::checkValidate($data, ['c_id', 'action']);

        if (!empty($data['c_id']) && !empty($data['action'])) {
            return verify_err (null,'分类id和分类标识只能传一个，不能共传！');
        }
        if (empty($data['c_id']) && empty($data['action'])) {
            return verify_err (null,'分类id和分类标识必须传一个，不能共传！');
        }
         return (new AdvLogic())->advTimeLimit($data);
    }

}
